home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 961 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.4 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: static members as members of a metacla
  5. Date: 04 Apr 1996 10:15:33 PST
  6. Organization: GABI Software, Sarl.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Apr4133331@gabi.gabi-soft.fr>
  9. References: <KANZE.96Mar29114545@gabi.gabi-soft.fr> <4jp7st$lbj@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 04 Apr 1996 11:33:31 GMT
  12. In-reply-to: clamage@Eng.Sun.COM's message of 01 Apr 1996 11:06:26 PST
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMWQRxky4NqrwXLNJAQFRVQIAvesCqlwMRSjLDXD9316xaor23l/klYm3
  15.     KC5fALDX5uH6Rlod9mqkW3vGE0unowSB4Ai4iGR3bM1BCjp7SREDYQ==
  16.     =OryE
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <4jp7st$lbj@engnews1.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve
  20. Clamage) writes:
  21.  
  22. |> In article 96Mar29114545@gabi.gabi-soft.fr, kanze@gabi-soft.fr (J. Kanze) writes:
  23. |> >In article <4jckdc$ad6@engnews1.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve
  24. |> >Clamage) writes:
  25. |> >
  26. |> >    [...]
  27. |> >|> I believe a reasonable solution to the problem of initialization of
  28. |> >|> non-local static data is not to use non-local static data!
  29. |> >
  30. |> >|> Instead of a static data object or static class data member, use a 
  31. |> >|> function with a local static object.
  32. |> >    [...]
  33. |> >|> Only two features are missing, compared to non-local static objects:
  34. |> >
  35. |> >|> 1. If you never reference an object, it is never initialized.
  36. |> >
  37. |> >But is this guaranteed by the standard anyway?  
  38.  
  39. |> Assuming a program terminates normally (returning from main or
  40. |> calling exit), I believe that every non-local static object defined
  41. |> in a module that is somehow referenced will eventually be intialized.
  42.  
  43. But the question concerned static objects in a module that was never
  44. referenced.  (What I'm thinking of here are objects whose constructor
  45. registers them with some sort of container, and that are only accessed
  46. via that container.  If they are constructed, they will be accessed.
  47. But is there any guarantee that they will eventually be constructed?)
  48.  
  49. |> >|> 2. The order of destruction remains unspecified. If that is a problem,
  50. |> >|> possibly the static objects could be of a type which has a do-nothing
  51. |> >|> destructor and a "destroy" member function which could be called
  52. |> >|> explicitly at the proper time.
  53. |> >
  54. |> >I thought that the order of destruction was the reverse of
  55. |> >initialization.
  56.  
  57. |> I believe the current draft says that. Few current implementations
  58. |> ensure that result, and whether that guarantee will remain in the standard
  59. |> is under discussion.
  60.  
  61. Good point.  It's true that I've yet to find a compiler that was conform
  62. with the draft on this point.  It would be a shame if the guarantee
  63. disappeared from the standard, however (unless there was something else
  64. equally good to replace it).
  65. -- 
  66. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  67. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  68. Conseils en informatique industrielle --
  69.                             -- Beratung in industrieller Datenverarbeitung
  70. ---
  71. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  72.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  73.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  74.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  75.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  76. ]
  77.